Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating and utilising a custom system image of Julia with RMS #2381

Closed
wants to merge 6 commits into from

Conversation

calvinp0
Copy link
Member

@calvinp0 calvinp0 commented Mar 2, 2023

Overview

In this pull request, I made several updates to PyJulia and the RMG website's instructions for running the system image create command. These changes include:

  • Updating the PyJulia channel to conda-forge
  • Adding an "if exists" statement to reactors.py to check if rms.so exists
  • Updating the website's instructions to explain how to run the command python -m julia.sysimage rms.so to create a customized system image

Benefits of Customized System Image

Creating a customized system image has several benefits, including:

  • Faster startup time: By precompiling code for specific packages, startup time can be significantly reduced.
  • Stability: By ensuring that a specific version of a package is used, the system image can provide a more stable environment for running Julia code.
  • Easier distribution: A customized system image can be distributed with a Julia package, making it easier for users to get started with the package.

Limitations of Customized System Image

There are also some limitations to using a customized system image, including:

  • Packages cannot be updated: PyCall and its dependencies cannot be updated after the system image is created. A new system image has to be created to update those packages.
  • Precompilation cache paths: The system image generated by julia.sysimage uses a different set of precompilation cache paths for each pair of julia-py executable and the system image file. Precompiled cache files generated by Julia or a different julia-py executable cannot be reused by PyJulia when using the system image generated by julia.sysimage.
  • Absolute path of julia-py: The absolute path of julia-py is embedded in the system image. This system image is not usable if julia-py is removed.

@calvinp0 calvinp0 requested review from mjohnson541 and kfir4444 March 2, 2023 17:44
@calvinp0 calvinp0 linked an issue Mar 2, 2023 that may be closed by this pull request
@JacksonBurns
Copy link
Contributor

Rebasing with fixed CI

@rwest
Copy link
Member

rwest commented May 15, 2023

@calvinp0 please could you update the description at the top of this pull request explaining the motivation, some background, and how this helps? Many of us (well, me at least!) are not as familiar with Julia (and PyJulia) and are trying to learn. Thanks.

Also, I note that the environment file currently in this PR still installs julia itself from the RMG channel (even though pyjulia comes from conda-forge). Can we move julia to the conda-forge channel too?

@calvinp0
Copy link
Member Author

@calvinp0 please could you update the description at the top of this pull request explaining the motivation, some background, and how this helps? Many of us (well, me at least!) are not as familiar with Julia (and PyJulia) and are trying to learn. Thanks.

Also, I note that the environment file currently in this PR still installs julia itself from the RMG channel (even though pyjulia comes from conda-forge). Can we move julia to the conda-forge channel too?

Sure, I will write a better description later tonight. I am not super familiar with Julia (never written Julia code) or PyJulia but I have become quite adept at debugging it over the last couple of months when errors occur.

Also, yes the environment file was out of date. I have rebased the branch with main.

Furthermore, even though this looks for the system image created, I have a feeling we will need to make changes to pyrms too. I will have to double check that. @mjohnson541 you are a bit more familiar with that package, does the code do the following:

from julia.api import Julia
jl = Julia(compiled_modules=False)

@calvinp0 calvinp0 requested a review from hwpang May 15, 2023 16:26
@rwest
Copy link
Member

rwest commented May 15, 2023

Thanks. I have been trying to follow along with the instructions (or some form of them). On an intel mac, with a conda environment containing (among other things)

julia                     1.7.2                h132cb31_0    conda-forge
pyjulia                   0.6.1              pyhd8ed1ab_0    conda-forge
diffeqpy                  1.1.0                     rmg_2    rmg
pyrms                     0.1.2                no_rmg_dep    rmg

I get (buried in a big error message)

ERROR: The following 2 direct dependencies failed to precompile:

DifferentialEquations [0c46a032-eb83-5123-abaf-570d42b7fbaa]

Error: Missing source file for DifferentialEquations [0c46a032-eb83-5123-abaf-570d42b7fbaa]
DiffEqBase [2b5f629d-d688-5b77-993f-72d75c75574e]

Error: Missing source file for DiffEqBase [2b5f629d-d688-5b77-993f-72d75c75574e]

during the python -m julia.sysimage rms.so step

@calvinp0
Copy link
Member Author

Thanks. I have been trying to follow along with the instructions (or some form of them). On an intel mac, with a conda environment containing (among other things)

julia                     1.7.2                h132cb31_0    conda-forge
pyjulia                   0.6.1              pyhd8ed1ab_0    conda-forge
diffeqpy                  1.1.0                     rmg_2    rmg
pyrms                     0.1.2                no_rmg_dep    rmg

I get (buried in a big error message)

DifferentialEquations [0c46a032-eb83-5123-abaf-570d42b7fbaa]

Error: Missing source file for DifferentialEquations [0c46a032-eb83-5123-abaf-570d42b7fbaa]
DiffEqBase [2b5f629d-d688-5b77-993f-72d75c75574e]

Error: Missing source file for DiffEqBase [2b5f629d-d688-5b77-993f-72d75c75574e]

during the python -m julia.sysimage rms.so step

I don't have access to an intel mac but I could try on my M1 using Rosetta and see what happens.

I assume you have already done the following command:

python -c "import julia; julia.install(); import diffeqpy; diffeqpy.install()"

julia -e 'using Pkg; Pkg.add(PackageSpec(name="ReactionMechanismSimulator",rev="main")); using ReactionMechanismSimulator;'

If so, was it recent? Because usually when I get Julia errors like this, I would rebuild rmg_env from scratch (although not delete the RMG-Py folder) and then re-run those two commands. If you are getting the same error, I can see if I can find an image of MacOS and install it on a virtual machine

@rwest
Copy link
Member

rwest commented May 16, 2023

I was going to suggest we rebase this once #2415 is merged. But I see you just closed it?

@rwest
Copy link
Member

rwest commented May 17, 2023

Checking chapter 5 of the pyJulia documentation suggests it might avoid the need to use python-jl to launch python?
Also from those doc

3.1 Your Python interpreter is statically linked to libpython

If you use Python installed with Debian-based Linux distribution such as Ubuntu or install Python by conda, you might have noticed that PyJulia cannot be initialized properly out-of-the-box. This is because those Python executables are statically linked to libpython

3.1.2 Create a custom system image

New in version 0.4.
A very powerful way to avoid this the issue due to precompilation cache is to create a custom system image. This also has an additional benefit that initializing PyJulia becomes instant. See Custom Julia system image for how to create and use a custom system image.

3.1.3 python-jl: an easy workaround New in version 0.2.

Another easy workaround is to use the python-jl command bundled in PyJulia

So it sounds to me like if we do a custom system image we don't need to use python-jl.
If we're not needing python-jl then we wouldn't need the customized version of it (ReactionMechanismGenerator/conda-recipes@b3f6136 ) that we were hosting on the rmg conda channel. I think this could address some of what @JacksonBurns was dealing with on #2415

The apparent time-to-launch benefit is attractive too.
@calvinp0 do you think this approach could help? Can we re-open the PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create system image of RMS using Julia
3 participants